package cn.yejinwen.action;

import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import net.sf.json.JSONArray;

import cn.chenjifeng.imple.OrderImple;
import cn.chenjifeng.model.Desk_Id_Mdeol;
import cn.yejinwen.impl.SelectDeskImpl;
import cn.yejinwen.model.Desk_id;
import cn.yejinwen.model.Order;

import com.opensymphony.xwork2.ActionSupport;

public class SelectDeskAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	HttpServletResponse response =  ServletActionContext.getResponse();
	HttpServletRequest request = ServletActionContext.getRequest();
	
	public String showDeskId() throws SQLException {    //查询可用餐桌id
     try{
    	ArrayList<Desk_Id_Mdeol> list_d_id;
 		OrderImple a = new OrderImple();
 		
 		list_d_id = a.SearchDeakId();
 		
 		String json_D_id = JSONArray.fromObject(list_d_id).toString();
 		response.reset();
 		response.setCharacterEncoding("UTF-8");
 		response.setContentType("text/html; charset=utf-8");
 		
 		PrintWriter pw = response.getWriter();
 		pw.write(json_D_id);
 		
 		return null;
	   }catch(Exception e){
			System.out.println(e.getStackTrace());
		}
     return SUCCESS;
	}
	
	/** 查询使用中的餐桌id	 */
	public String showUseing_D_id() throws SQLException{
		try{
		ArrayList<Desk_id> list_d_id;
		SelectDeskImpl sele_d = new SelectDeskImpl();
 		
 		list_d_id =sele_d.showUseing_Desk();
 		
 		String json_D_id = JSONArray.fromObject(list_d_id).toString();
 		response.reset();
 		response.setCharacterEncoding("UTF-8");
 		response.setContentType("text/html; charset=utf-8");
 		
 		PrintWriter pw = response.getWriter();
 		pw.write(json_D_id);
 		
 		return null;
	   }catch(Exception e){
			System.out.println(e.getStackTrace());
		}
     return SUCCESS;		
	}
	
}
